package com.atguigu.gulimail.product.demo;

import org.junit.jupiter.api.Test;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Set;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.stream.LongStream;

/**
 * @author fangy
 * @date 2022-08-20 11:00
 */
public class TestForkJoin {


    /**
     * fork-join框架  3240
     */
    @Test
    public void test1(){

        Instant start = Instant.now();


        ForkJoinPool pool = new ForkJoinPool();
        ForkJoinTask<Long> task = new ForkJoinCalculate(0, 10000000000L);
        Long sum = pool.invoke(task);

        Instant end = Instant.now();

        System.out.println("耗费时间："+ Duration.between(start,end).toMillis());


    }


    /**
     * 普通for  4752
     */
    @Test
    public void test2(){


        Instant start = Instant.now();

        long sum = 0L;

        for (long i = 0; i <= 10000000000L; i++){
            sum += i;
        }

        System.out.println(sum);


        Instant end = Instant.now();

        System.out.println("耗费时间："+ Duration.between(start,end).toMillis());


    }

    /**
     * java8并行流  1400
     */
    @Test
    public void test3(){

        Instant start = Instant.now();

        LongStream.rangeClosed(0,10000000000L)
                  .parallel()
                  .reduce(0,Long::sum);

        Instant end = Instant.now();

        System.out.println("耗费时间："+ Duration.between(start,end).toMillis());

    }

    @Test
    public void test4(){

        Instant instant = Instant.now();
        System.out.println(instant);

        OffsetDateTime time = instant.atOffset(ZoneOffset.ofHours(8));
        System.out.println(time);

        System.out.println(instant.toEpochMilli());

        Instant instant1 = Instant.ofEpochSecond(60);
        System.out.println(instant1);

    }

    @Test
    public void test5(){

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime now = LocalDateTime.now();

        String format = formatter.format(now);
        System.out.println(format);

    }

    @Test
    public void test8(){

        Set<String> ids = ZoneId.getAvailableZoneIds();

        ids.forEach(System.out::println);

    }


}
